package cn.intent;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /*显式调用*/
        findViewById(R.id.sim1_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                //第一种
//              intent.setClass(MainActivity.this,FirstRestaurantActivity.class);

                //第二种
                // setClassName("包名","包名.Activity")
                String className = "cn.activity.StudentActivity";
//                intent.setClassName(MainActivity.this,classNa me);


                //第三种
                String packageName = "cn.intent";
                intent.setClassName(packageName,className);

                startActivity(intent);
            }
        });

        /*隐式调用(action)*/
        findViewById(R.id.sim2_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("I_WANT_TO_EAT");
                startActivity(intent);
            }
        });

        /*隐式调用(action+Category)*/
        findViewById(R.id.sim3_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("I_WANT_TO_EAT");
                intent.addCategory("NIU_ROU_FAN");
                startActivity(intent);
            }
        });

        /*intent启动系统应用*/
        findViewById(R.id.sim4_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://www.baidu.com"));
                startActivity(intent);
            }
        });
    }
}
